﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Scheduler
{
    // 
    public class SchedulerManager
    {
        //
        public Dictionary<string, SchedulerGroup> DispatcherGroups
        {
            get
            {
                Dictionary<string, SchedulerGroup> result;
                if ((result = this._dispatcherGroups) == null)
                {
                    result = (this._dispatcherGroups = new Dictionary<string, SchedulerGroup>());
                }
                return result;
            }
            set
            {
                this._dispatcherGroups = value;
            }
        }

        //
        public void AddDispatchers(string groupFullName, List<IScheduler> dispatchers, bool isSort)
        {
            if (dispatchers == null || this.DispatcherGroups.ContainsKey(groupFullName))
            {
                return;
            }
            SchedulerGroup dispatcherGroup = new SchedulerGroup(dispatchers, isSort);
            this.DispatcherGroups.Add(groupFullName, dispatcherGroup);
            dispatcherGroup.Start();
        }

        // 
        public void RemoveDispatchers(string groupFullName)
        {
            if (this.DispatcherGroups.ContainsKey(groupFullName))
            {
                this.DispatcherGroups[groupFullName].Stop();
                this.DispatcherGroups.Remove(groupFullName);
            }
        }

        // 
        public void Start()
        {
        }

        // 
        public void Stop()
        {
            foreach (SchedulerGroup dispatcherGroup in this.DispatcherGroups.Values)
            {
                dispatcherGroup.Stop();
            }
            this.DispatcherGroups.Clear();
        }

        // 
        private Dictionary<string, SchedulerGroup> _dispatcherGroups;
    }
}
